package acwing.每日一题;/**
 * @author： li
 * @date： 2022-03-25 15:55
 * @version 1.0
 */
import java.util.*;
public class 果壳游戏 {
    static int n;
    static int[][] change;
    static boolean[] flag;
    static int score(){
        int res=0;
        for(int i=1;i<=n;i++){
            boolean c = flag[change[i][1]];
            flag[change[i][1]] = flag[change[i][2]];
            flag[change[i][2]] = c;
            if(flag[change[i][3]])
                res++;
        }
        return res;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        change = new int[n+1][4];
        flag = new boolean[4];
        for(int i=1;i<=n;i++)
            for(int j=1;j<=3;j++) {
                change[i][j] = sc.nextInt();
            }
        int res1=0,res2=0,res3=0;
        Arrays.fill(flag,false);
        flag[1]=true;
        res1=score();
        Arrays.fill(flag,false);
        flag[2]=true;
        res2=score();
        Arrays.fill(flag,false);
        flag[3]=true;
        res3=score();
//        System.out.println("res1="+res1+"res2="+res2+"res3="+res3);
        System.out.println(Math.max(Math.max(res1,res2),res3));
    }
}
